home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Cafe 3
/
Visual Cafe 3.ISO
/
Vcafe
/
Main.bin
/
EventBroadcaster.java
< prev
next >
Wrap
Text File
|
1998-09-22
|
2KB
|
111 lines
package com.symantec.itools.beans;
import java.lang.reflect.Method;
import java.util.EventListener;
import java.util.EventObject;
import java.util.Enumeration;
import java.util.Vector;
/**
* EventBroadcaster provides a generic way to broadcast events
* to a group of listeners.
*
* @author Symantec Internet Tools Division
* @version 1.0
* @since VCafe 3.0
*/
public class EventBroadcaster
{
/**
* @since VCafe 3.0
*/
protected Vector listeners;
{
listeners = new Vector();
}
public EventBroadcaster()
{
}
/**
* @param listener TODO
* @param unique TODO
* @since VCafe 3.0
*/
public synchronized void addListener(EventListener listener, boolean unique)
{
if(unique)
{
if(listeners.contains(listener))
{
return;
}
}
listeners.addElement(listener);
}
/**
* @param listener TODO
* @param all TODO
* @since VCafe 3.0
*/
public synchronized void removeListener(EventListener listener, boolean all)
{
listeners.removeElement(listener);
if(all)
{
while(listeners.removeElement(listener))
{
}
}
}
/**
* @param event TODO
* @param methodName TODO
* @since VCafe 3.0
*/
public void fireEvent(EventObject event, String methodName)
{
Vector fireToListeners;
Class[] argIDs;
EventObject[] args;
synchronized(listeners)
{
fireToListeners = (Vector)listeners.clone();
}
argIDs = new Class[1];
argIDs[0] = event.getClass();
args = new EventObject[1];
args[0] = event;
for(Enumeration e = fireToListeners.elements(); e.hasMoreElements();)
{
try
{
EventListener listener;
Method method;
listener = (EventListener)e.nextElement();
method = listener.getClass().getMethod(methodName, argIDs);
method.invoke(listener, args);
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
}